home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Joystick Magazine 1995 July & August
/
cd No4 joystick No62.iso
/
mac
/
pc
/
SHARE
/
LIGHTLIB
/
LANGUAGE.Z
/
LLIDDOC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-23
|
14KB
|
392 lines
// LLIDdoc.cpp : implementation of the CLLIDDoc class
//
#include "stdafx.h"
extern "C" // include your LightLibImage - header file here
{
#include "LLI.H"
}
#include "LLID.h"
#include "LLIDdoc.h"
#include "LLIDview.h" // added to access to the view
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLLIDDoc
IMPLEMENT_DYNCREATE(CLLIDDoc, CDocument)
BEGIN_MESSAGE_MAP(CLLIDDoc, CDocument)
//{{AFX_MSG_MAP(CLLIDDoc)
ON_COMMAND(ID_GEN_MOSAIC, OnGenMosaic)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLLIDDoc construction/destruction
CLLIDDoc::CLLIDDoc()
{
// TODO: add one-time construction code here
lloImage = 0;
lloOrigImage = 0;
}
/////////////////////////////////////////////////////////////////////////////
CLLIDDoc::~CLLIDDoc()
{
// do clean up
if( lloImage )
lloImage = oDel( lloImage );
if( lloOrigImage )
lloOrigImage = oDel( lloOrigImage );
}
/////////////////////////////////////////////////////////////////////////////
BOOL CLLIDDoc::OnNewDocument()
{
// we will create a new image by reading it from scanner
// Load new cursor and sve the old one
HCURSOR oldCursor;
oldCursor = SetCursor( LoadCursor( 0, IDC_WAIT ) );
POSITION pos = GetFirstViewPosition();
CLLIDView* pView = (CLLIDView *)GetNextView( pos );
pView->IdleStart(20);
lloImage = iGet( lloApp, // Applic.handle created with oNew
LLI_SCANNER, // source : read from scanner
LLI_SCANNER_TWAIN, // scanner type
0, // upper left corner X
0, // upper left corner Y
-1, // lower right corner X
-1, // lower right corner Y
0, // density
0, // luminosity
0, // contrast
0, // - not used -
0, // - not used -
(DWORD)pView ); // userparameter
pView->IdleStop();
// retreive old cursor
SetCursor ( oldCursor );
if(! lloImage )
{
lloImage = iGet( lloApp, // LightLibObject application handle
LLI_MEMORY, // source
LLI_MEMORY_16, // 16 color mode
0, // upper left corner X
0, // upper left corner Y
100, // lower right corner X
100, // lower right corner Y
0, // - not used -
0, // - not used -
0, // - not used -
0, // - not used -
0, // - not used -
0 ); // - not used -
}
else
{
// don't allow images with more colors than display can handle
short val = (short)oAccess( lloImage, LLI_IMAGE_BITS, 0 );
CDC dc;
int ScreenCap = dc.GetDeviceCaps( DT_RASDISPLAY );
if ( (val == 24) && ( ScreenCap < 16 ) )
{
AfxMessageBox( (LPCSTR)"Video settings too low"
"Too many colors for this image to be displayed" );
CDocument::OnNewDocument();
return FALSE;
}
else // if videomode is <= 256 colors then use shared palette, else use exclusive one
{
CLLIDView* pView = (CLLIDView *)GetNextView( pos );
if ( ScreenCap <= 256 )
{
pView->ExclusivePaletteIsActive = LLI_PALETTE_EXCLUSIVE;
}
else
{
pView->ExclusivePaletteIsActive = LLI_PALETTE_SHARED;
}
}
}
// keep a copy of original
if( lloImage )
{
lloOrigImage = iCopy( lloImage, // pointer to image
0, // upper left corner X
0, // upper left corner Y
-1, // lower right corner X
-1, // lower right corner Y
LLI_COPY_CLONE,// just make a copy
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0 ); // userparameter
}
CDocument::OnNewDocument();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CLLIDDoc serialization
void CLLIDDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
CDocTemplate * cTmp = GetDocTemplate();
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CLLIDDoc diagnostics
#ifdef _DEBUG
void CLLIDDoc::AssertValid() const
{
CDocument::AssertValid();
}
/////////////////////////////////////////////////////////////////////////////
void CLLIDDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLLIDDoc commands
void CLLIDDoc::DeleteContents() // clean up when closing or reopening a document
{
if ( lloImage )
{
lloImage = oDel( lloImage );
}
if ( lloOrigImage )
{
lloOrigImage = oDel( lloOrigImage );
}
}
/////////////////////////////////////////////////////////////////////////////
BOOL CLLIDDoc::OnOpenDocument( const char *pszPathName )
{
// TODO: Add your command handler code here
// read an image from disk
POSITION pos = GetFirstViewPosition();
CLLIDView* pView = (CLLIDView *)GetNextView( pos );
pView->IdleStart(20);
lloImage = iGet( lloApp, // Applic.handle created with oNew
LLI_DISK, // source : read from disk
0, // format : autodetect
0, // upper left corner X
0, // upper left corner Y
-1, // lower right corner X
-1, // lower right corner Y
(DWORD)pszPathName, // path and filename
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
(DWORD)pView ); // userparameter
pView->IdleStop();
if(! lloImage )
{
lloImage = iGet( lloApp, // LightLibObject application handle
LLI_MEMORY, // source
LLI_MEMORY_16, // 16 color mode
0, // upper left corner X
0, // upper left corner Y
100, // lower right corner X
100, // lower right corner Y
0, // - not used -
0, // - not used -
0, // - not used -
0, // - not used -
0, // - not used -
0 ); // - not used -
}
// if load was successful then keep a copy of original
lloOrigImage = iCopy( lloImage, // pointer to image
0, // upper left corner X
0, // upper left corner Y
-1, // lower right corner X
-1, // lower right corner Y
LLI_COPY_CLONE,// just make a copy
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
0 ); // userparameter
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////
BOOL CLLIDDoc::OnSaveDocument( const char *pszPathName )
{
// TODO: Add your command handler code here
// We need a pointer to the corresponding view in order to get
// information about the selected capture region
// To get the first view in the list of views assigned to this document:
POSITION pos = GetFirstViewPosition();
CLLIDView* pView = (CLLIDView *)GetNextView( pos );
if( lloImage )
{
CRect rTmp;
rTmp = pView->GetSelection(); // get the selected capture rectangle
// To avoid the implementation of a class for each image type,
// we simply read the extension of the filename, the user typed
// in the SaveAs dialogbox and then make up a decision about the
// format the image will be saved in.
DWORD iType;
char *ExtStr;
// point to extension
ExtStr = (char*)pszPathName + strlen( pszPathName ) -4;
// compare extension
if ( strcmp( ExtStr,".GIF") == 0 ) iType = LLI_DISK_GIF;
else if ( strcmp( ExtStr, ".JPG") == 0 ) iType = LLI_DISK_JPG;
else if ( strcmp( ExtStr, ".PCX") == 0 ) iType = LLI_DISK_PCX;
else if ( strcmp( ExtStr, ".TIF") == 0 ) iType = LLI_DISK_TIF;
else iType = LLI_DISK_BMP;
// if we did not find a match, we simply save as a Bitmap (*.BMP)
pView->IdleStart(20);
iPut( lloImage, // pointer to image
rTmp.left, // upper left corner X
rTmp.top, // upper left corner Y
rTmp.right, // lower right corner X
rTmp.bottom, // lower right corner Y
LLI_DISK, // destination disk
iType, // image type (format)
0, // horizontal offset in the file
0, // vertical offset in the file
(DWORD)pszPathName, // path and filename
0, // compression type
0, // - not used in this case -
0, // - not used in this case -
0, // - not used in this case -
(DWORD)pView ); // userparameter
pView->IdleStop();
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////////////////
CSize CLLIDDoc::GetImageSize( BOOL OrigImage )
{
// Get the horizontal and vertical size of the image.
// This method is used by the LLIDView class to obtain
// either the size of the original image or the current
// image (propably different)
CSize xy;
int xx=0, yy=0;
if ( (!lloOrigImage) || (!lloImage) )
{
xy.cx = 0;
xy.cy = 0;
return xy;
}
switch ( OrigImage )
{
case TRUE :
// the caller desires the original size
xx = (int)oAccess( lloOrigImage, LLI_IMAGE_WIDTH, 0 );
yy = (int)oAccess( lloOrigImage, LLI_IMAGE_HEIGHT, 0 );
break;
case FALSE :
default:
// the caller desires the current size
xx = (int)oAccess( lloImage, LLI_IMAGE_WIDTH, 0 );
yy = (int)oAccess( lloImage, LLI_IMAGE_HEIGHT, 0 );
}
xy.cx = xx;
xy.cy = yy;
return xy;
}
///////////////////////////////////////////////////////////////////////////////////////////
void CLLIDDoc::OnGenMosaic()
{
// we first create an empty image of a certain size and then copy
// all images currently loaded into it. ( tile )
CSize mSize;
mSize.cx = 500; // the mosaic's width
mSize.cy = 300; // the mosaic's height
// now get all the images currently open
AfxMessageBox( (LPCSTR)"Option not yet available");
}